local skel = fk.CreateSkill {
  name = "emo__qiyue",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__qiyue"] = "契约",
  [":emo__qiyue"] = "①锁定技，每当你进入濒死状态时，若有横置的角色，你重置这些角色并摸等量张牌，且令〖支配〗于本回合失效，然后你将体力值恢复至1点。②锁定技，当你死亡时，将一张“生姜炒肉”洗入牌堆。",

  ["$emo__qiyue1"] = "言うことを聞かない犬は要らない",
  ["$emo__qiyue2"] = "助けて、チェンソーマン",
}

skel:addEffect(fk.EnterDying, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and table.find(player.room.alive_players, function(p) return p.chained end)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local x = 0
    for _, p in ipairs(room.alive_players) do
      if p.chained then
        p:setChainState(false)
        x = x + 1
      end
    end
    if x > 0 and not player.dead then
      player:drawCards(x, skel.name)
    end
    if player.dead then return end
    room:invalidateSkill(player, "emo__zhipei", "-turn")
    if player:isWounded() then
      room:recover { num = 1 - player.hp, skillName = skel.name, who = player , recoverBy = player}
    end
  end,
})

skel:addEffect(fk.Death, {
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name, false, true) and target == player
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local copy_card = Fk.all_card_types["makima__peach"]
    if copy_card == nil then return end
    local cid = table.find(room.void, function (id) return Fk:getCardById(id).name == "makima__peach" end)
    if not cid then
      cid = room:printCard("makima__peach", copy_card.suit, copy_card.number).id
    end
    room:moveCards ({
      ids = {cid},
      toArea = Card.DrawPile,
      moveReason = fk.ReasonJustMove,
      skillName = skel.name,
      drawPilePosition = math.random(#room.draw_pile),
    })
  end,
})

return skel
